/*
 * Master.h
 *
 *  Created on: May 13, 2011
 *      Author: stud
 */

#ifndef MASTER_H_
#define MASTER_H_


#include "SerialPort.h"
#include "MemoryMaps.h"
#include "Thread.h"
#include "ModbusProtocol.h"

#define QUERY_BUFF_SIZE 10
#define BUFFER_SIZE 45

class Master : public Thread
{


private:
	mbPacket packetIn;
	mbPacket packetOut;


	ModbusProtocol * protocol;

	mbPacket queries[QUERY_BUFF_SIZE];

	unsigned char buffer[BUFFER_SIZE];

	MemoryMaps * _maps;

public:

	SerialPort * xbee;

	Master(ThreadPriority pri = Thread::PRIORITY_NORMAL, string _name = "", MemoryMaps * mapManager = NULL,char * device = NULL, int baudRate = 0);
	~Master();

	virtual void run();


	void issueQuery();

	void flushQueryBuffer();

	mbPacket getPacketIn();
	mbPacket getPacketOut();

	void flushPacketBuffer();

	void executeRead();

	void executeWrite();

	void executeWrite(sWord * dataOut, int len);
};

#endif /* MASTER_H_ */
